<?php
namespace app\libs\security;

class Crypt3DES {

    private $key;
    private $iv = '@!tahw..';  // 8 length

    public function __construct($key) {
        $this->key = $key;
    }

    /**
     * 加密
     */
    public function encrypt($data) {
        $ret = openssl_encrypt($data, 'DES-EDE3-CBC', $this->key, OPENSSL_RAW_DATA, $this->iv);

        return base64_encode($ret);
    }

    /**
     * 解密
     */
    public function decrypt($data) {
        $ret = base64_decode($data);

        return openssl_decrypt($ret, 'DES-EDE3-CBC', $this->key, OPENSSL_RAW_DATA, $this->iv);
    }

}

